var app = getApp();
Page({
    data:{
        page : {
            isend : false,
            doing : false,
            doo : 'kefu',
            pdata : {
                op : 'mylist',
                page : 1,
                status : 0,
            },
            waitf : 0,
            nodataf : 0,
        },
        datalist : [],
        timer : null,
		siteroot : app.siteInfo.siteroot.replace('app/index.php', ''),uniacid: app.siteInfo.uniacid,
    },
    onLoad:function(options){
        var self = this;

        if( options.scene ){
            var list = options.scene.split('_');
            options.role = list[0] ? list[0] : 0;
            options.shopid = list[1] ? list[1] : 0;
            options.uid = list[2] ? list[2] : 0;
        }
		
		var shopid = options.shopid ? options.shopid : '';
        
        var zfid = options.zfid ? options.zfid : '';
        var role = options.role ? options.role : 'user';
        
        var uid = options.uid ? options.uid : '';
        self.setData({
            options : options,
            'page.pdata.status' : options.status ? options.status : 0,
            'page.pdata.zfid' : zfid,
            'page.pdata.role' : role,
            'page.pdata.shopid' : shopid,
            'page.pdata.uid' : uid,
            'page.pdata.page' : 1,
        });

        app.com.auth(function(user){
            app.com.getPage(self,self.data.page,0,function(res){
                var data = res.data.data;
                self.setData({
                   datalist : data.list,
                   Pagetheme : res.data.data.params.style,
                   sharedata : data.sharedata,
                },function(){
                    if( !self.data.inited ){
                        self.setData({
                            inited : true,
                        });
                        wx.setNavigationBarTitle({
                            title : '对话列表',
                        });
                    }
                });

            },false,function(res){
                app.com.alert(res.data.message,function(){
                    app.com.backPage(0);
                });
            });
			app.com.setBar(app,self,shopid);
        });
        self.getnew();
    },
    onShareAppMessage : function(){
        var self = this;
        return {
            title: self.data.sharedata.title,
            path: self.data.sharedata.path,
            imageUrl : self.data.sharedata.img,
        }
    },
    onShow(){
        if( this.data.inited ){
            this.getnew();
        }
    },
    onUnload(){
        clearInterval(this.data.timer);
    },
    onHide(){
        clearInterval(this.data.timer);
    },
    onPullDownRefresh: function () {
        if( this.data.isdown ) return false;
        this.setData({
            isdown : true,
        });
        
        this.onLoad( this.data.options );
        this.setData({
            isdown : false,
        });
        wx.stopPullDownRefresh();
    },
    getnew(){
        var self = this;
        clearInterval(self.data.timer);
        self.data.timer = setInterval(function(){
            self.onPullDownRefresh();
        },8000);
    },
    location : function( e ){
        app.com.location( e );
    },
    otherapp : function( e ){
        app.com.otherapp( e );
    },
    navigateto : function( e ){
        var sid = e.currentTarget.dataset.sid;
        if( sid ){
            for (var i = 0; i < this.data.datalist.length; i++) {
                if(this.data.datalist[i].id == sid){
                    this.setData({
                        ['datalist['+i+'].status'] : 1,
                    })
                }
            }
        }

        wx.navigateTo({
            url : e.currentTarget.dataset.url
        });
    },
    redirectto : function( e ){
        app.com.redirectto( e );
    },    
    callphone : function(e){
        app.com.callphone( e );
    },
    toweburl : function(e){
        app.com.toweburl( e );
    },
    showimages : function( e ){
        app.com.showimages( e );
    },
    footNavigate(e){
        var url = e.currentTarget.dataset.url;
        wx.switchTab({
          url: url
        })
    },    

})